package com.lefevre.cms.bean.question;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 问题标签
 *
 * @author Lefevre
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("question_tag")
@Entity
@Table(name = "question_tag", indexes = {@Index(name = "question_tag_1_idx", columnList = "sort")})
public class QuestionTag implements Serializable {
    private static final long serialVersionUID = -811884294168718523L;

    @Id
    @TableId(type = IdType.INPUT)
    private Long id;

    /**
     * 标签名称
     **/
    @Column(length = 190)
    @TableField("`name`")
    private String name;

    /**
     * 所属父类ID
     **/
    @TableField("parentId")
    private Long parentId = 0L;

    /**
     * 父Id组  顺序存放
     **/
    @Column(length = 190)
    @TableField("parentIdGroup")
    private String parentIdGroup = ",0,";

    /**
     * 子节点数量
     **/
    @TableField("childNodeNumber")
    private Integer childNodeNumber = 0;

    /**
     * 子标签
     **/
    @Transient
    @TableField(exist = false)
    private List<QuestionTag> childTag = new ArrayList<>();

    /**
     * 排序
     **/
    @TableField("sort")
    private Integer sort = 0;

    /**
     * 添加子标签
     **/
    public void addChildTag(QuestionTag questionTag) {
        this.getChildTag().add(questionTag);
    }

}

